package com.rk.cust.infra.persistence.assembler;

import com.rk.cust.domain.entity.Cust;
import com.rk.cust.domain.vo.CertType;
import com.rk.cust.domain.vo.CustStatus;
import com.rk.cust.infra.persistence.po.CustPo;
import org.springframework.stereotype.Component;

@Component
public class CustPoAssembler {

    public Cust assembler(CustPo custPo) {
        Cust cust = new Cust();
        if (null != custPo) {
            cust.setId(custPo.getId());
            cust.setCorporation(custPo.getCorporation());
            cust.setCertType(CertType.of(custPo.getCertType()));
            cust.setCertNo(custPo.getCertNo());
            cust.setStatus(CustStatus.of(custPo.getStatus()));
            cust.setCreateTime(custPo.getCreateTime());
            cust.setLastUpdateTime(custPo.getLastUpdateTime());
        }
        return cust;
    }

    public CustPo assembler(Cust cust) {
        CustPo custPo = new CustPo();
        if (null != cust) {
            custPo.setId(cust.getId());
            custPo.setCorporation(cust.getCorporation());
            custPo.setCertType(null == cust.getCertType() ? null:cust.getCertType().getType());
            custPo.setCertNo(cust.getCertNo());
            custPo.setStatus(null == cust.getStatus() ? null: cust.getStatus().getStatus());
        }
        return custPo;
    }
}
